package com.clss.emergencycall.base;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.location.LocationManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.os.Build;
import android.os.Bundle;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.clss.emergencycall.R;
import com.clss.emergencycall.bean.BaseJson;
import com.clss.emergencycall.fuction.login.LoginActivity;
import com.clss.emergencycall.popAndDialog.LoadingDialog;
import com.clss.emergencycall.tools.eventbus.EventBusHelper;
import com.clss.emergencycall.tools.eventbus.EventBusMessage;
import com.clss.emergencycall.utils.ActivityTracker;
import com.clss.emergencycall.utils.AppUtils;
import com.clss.emergencycall.utils.ClueUtil;
import com.clss.emergencycall.utils.Lg;
import com.clss.emergencycall.utils.PublicUtils;
import com.clss.emergencycall.utils.SpHelper;
import com.clss.emergencycall.utils.Tools;
import com.clss.emergencycall.utils.VersionUpdataHelper;
import com.clss.emergencycall.view.GrayFrameLayout;

import org.apache.commons.lang3.ArrayUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.clss.emergencycall.base.Constant.REQUEST_CODE_CAMARE;
import static com.clss.emergencycall.base.Constant.REQUEST_CODE_IMAGE;
import static com.clss.emergencycall.base.Constant.REQUEST_CODE_VIDEO;

/**
 * Activity类的父类
 * Created by Liuv on 2017/4/12.
 */

public abstract class BaseActivity extends AppCompatActivity implements BaseView, GeocodeSearch.OnGeocodeSearchListener {
    private static final String TAG = "BaseActivity";
    protected ProgressDialog mProgressDialog;
    private List<VersionUpdataHelper.CustomDialog> mCustomDialogs = new ArrayList<>();
    public LoadingDialog loadDialog;
    public Animation fade_in;
    public Animation fade_out;

    private AMapLocationClient locationClient = null;
    private AMapLocationClientOption locationOption = null;

    protected File mCamareFile;
    GeocodeSearch geocoderSearch;

    @Nullable
    @Override
    public View onCreateView(@NonNull String name, @NonNull Context context, @NonNull AttributeSet attrs) {
        if(Constant.showBlackView) {
            getWindow().setStatusBarColor(Color.GRAY);
            if ("FrameLayout".equals(name)) {
                int count = attrs.getAttributeCount();
                for (int i = 0; i < count; i++) {
                    String attributeName = attrs.getAttributeName(i);
                    String attributeValue = attrs.getAttributeValue(i);
                    if (attributeName.equals("id")) {
                        int id = Integer.parseInt(attributeValue.substring(1));
                        String idVal = getResources().getResourceName(id);
                        if ("android:id/content".equals(idVal)) {
                            GrayFrameLayout grayFrameLayout = new GrayFrameLayout(context, attrs);
                            return grayFrameLayout;
                        }
                    }
                }
            }
        }
        return super.onCreateView(name, context, attrs);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ActivityTracker.onCreate(this);
        fade_in = AnimationUtils.loadAnimation(this, R.anim.fade_in);
        fade_out = AnimationUtils.loadAnimation(this, R.anim.fade_out);
        setContentView(setViewId());
        getWindow().setBackgroundDrawable(null);
        EventBus.getDefault().register(this);
        initView();
        initData(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        Lg.i(TAG, "onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        Lg.i(TAG, "onPause");
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        destroyLocation();
        dismissLoadingDialog();
        super.onDestroy();
        ActivityTracker.onDestory(this);
        Lg.i(TAG, "onDestroy");
        if (loadDialog != null)
            loadDialog = null;
    }

    protected abstract int setViewId();

    protected abstract void initView();

    protected abstract void initData(@Nullable Bundle savedInstanceState);

    @SuppressLint("NewApi")
    @Subscribe
    public void onEventMainThread(EventBusMessage eventBusMessage) {
        switch (eventBusMessage.getCode()) {
            case EventBusMessage.OR_SWITCH_LOCATION:
                Lg.i(TAG, "onEventMainThread: 更新了位置");
                upDateIp(eventBusMessage.getAMapLocation());
                break;
            case Constant.SESSION_TIMEOUT:
                logout();
                break;
            case EventBusHelper.HAS_NEW_TEXT_CALL:
                showTextCallDialog(eventBusMessage.getMessage(), eventBusMessage.getStr2());
                break;
            case EventBusMessage.SEND_ALL_BLOCK_WINDOW:
                deleteAllDialog();
                break;
            case EventBusHelper.EVENT_ALARM_CASE_HANDLE_NOTICE:
//                if (AppUtils.getTopActivity(this).
//                        contains(HistoryDetailActivity.class.getSimpleName())){
//                }else {
//                    ChatHelper.addWebRtcNotication(this, eventBusMessage.getMessage(), eventBusMessage.getStr2());
//                }
                break;
            default:
        }
    }

    /**
     * 消除警情沟通多余消息
     */
    private void deleteAllDialog() {
        for (VersionUpdataHelper.CustomDialog dialog : mCustomDialogs) {
            if (dialog != null && dialog.isShowing()) {
                dialog.dismiss();
            }
        }
    }

    protected synchronized void logout() {
        Lg.i(TAG, "---logout===" + AppUtils.getTopActivity(this));
        if (AppUtils.getTopActivity(this).contains(LoginActivity.class.getSimpleName())){
            return;
        }
//        if(PushConstant.Companion.isBrandHuawei()) {
            //删了好像就注册不了了
//            HMSAgent.Push.deleteToken(SpHelper.getInstance().getPushRegId(), rst -> Lg.i(TAG, "---deleteRst===" + rst));
//        }
//        if(PushConstant.Companion.isBrandXiaoMi()) {
//            MiPushClient.unregisterPush(this);
//        }
//        if(PushConstant.Companion.isBrandOppo()) {
//            PushManager.getInstance().unRegister();
//        }
//        new PushModel(getActContext()).clearPushReg(new Callback<BaseJson>(){
//            @Override
//            public void onResponse(Call<BaseJson> call, Response<BaseJson> response) {
//                BaseJson baseJson = response.body();
//                if (baseJson != null){
//                    Lg.i(TAG,"---pushReg---onResponse==="+baseJson);
//                }
//            }
//
//            @Override
//            public void onFailure(Call<BaseJson> call, Throwable t) {
//                Lg.i(TAG,"---pushReg---onFailure===");
//            }
//        });
        SpHelper.getInstance().clearAll();
        Intent intent = new Intent(this, LoginActivity.class);
        intent.putExtra(LoginActivity.TYPE, "1");
        startActivity(intent);
        ActivityTracker.finishAll();
        EventBusHelper.sendEventBusMsg(EventBusHelper.STOP_STOMP_KEEP_ALIVE);
//        AppDatabaseHelper.Companion.getInstance().deleteHostServices();
//        AppDatabaseHelper.Companion.getInstance().deleteHomeMenus();
//        AppDatabaseHelper.Companion.getInstance().deleteMenuGroups();
//        AppDatabaseHelper.Companion.getInstance().deleteMineMenus();
    }

    @Override
    public void showLoadingDialog() {
        runOnUiThread(() -> showLoadingDialog(null, getString(R.string.please_wait)));
    }

    @Override
    public void showLoadingDialog(String msg) {
        runOnUiThread(() ->showLoadingDialog(null, msg));
    }

    public void showLoadingDialog(String title, String message) {
        if (isDestroyed() || isFinishing()){
            return;
        }
        if (mProgressDialog == null) {
            mProgressDialog = new ProgressDialog(this, 5);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        }

        if (title == null) {
            title = "";
        }
        if (message == null) {
            message = "";
        }
        mProgressDialog.setTitle(title);
        mProgressDialog.setMessage(message);
        mProgressDialog.show();
    }

    @Override
    public void dismissLoadingDialog() {
        runOnUiThread(() -> {
            if (mProgressDialog != null && mProgressDialog.isShowing()) {
                mProgressDialog.dismiss();
            }
        });
    }

    public void showLoadDialog() {
        runOnUiThread(() -> {
            if (loadDialog == null) {
                loadDialog = AppUtils.getCricleDialog(this);
            }
            if (!loadDialog.isShowing())
                loadDialog.show();
        });
    }

    public void dismissLoaddialog() {
        runOnUiThread(() -> {
            if (loadDialog != null && loadDialog.isShowing())
                loadDialog.dismiss();
        });
    }

    @Override
    public Context getActContext() {
        return this;
    }

    protected void showLongToast(int messageId) {
        showLongToast(getString(messageId));
    }

    protected void showLongToast(final String message) {
        runOnUiThread(() -> Toast.makeText(getActContext(), message, Toast.LENGTH_LONG).show());
    }

    protected void showShortToast(int messageId) {
        showShortToast(getString(messageId));
    }

    protected void showShortToast(final String message) {
        if (message.equals("")) {
            return;
        }
        runOnUiThread(() -> Toast.makeText(getActContext(), message, Toast.LENGTH_SHORT).show());
    }

    protected void showTextCallDialog(String roomId, String caseId){
//        if (this.getClass().getSimpleName().equals(ChatRoomActivity.class.getSimpleName())
//                || this.getClass().getSimpleName().equals(WebRtcActivity.class.getSimpleName())
//                || this.getClass().getSimpleName().equals(LoginActivity.class.getSimpleName())) {
//            Lg.i(TAG, "---HAS_NEW_TEXT_CALL===" + this.getClass().getSimpleName());
//            return;
//        }
//        deleteAllDialog();
//        Lg.i(TAG, "---this.getClass().getSimpleName()===" + this.getClass().getSimpleName());
//        Lg.i(TAG, "---ActivityTracker.getFirstActivityName()===" + ActivityTracker.getFirstActivityName());
//        if (this.getClass().getSimpleName().equals(ActivityTracker.getFirstActivityName())) {
//            Ringtone ringtone = RingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI);
//            ringtone.play();
//            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
//            long[] l = {2000, 2000, 2000};
//            if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
//                VibrationEffect vibrationEffect = VibrationEffect.createWaveform(l, 1);
//                v.vibrate(vibrationEffect);
//            } else {
//                v.vibrate(l,1);
//            }
//            runOnUiThread(() -> {
//                VersionUpdataHelper.CustomDialog mCustomDialog = showInteractionDialog("民警找你沟通案情，是否接受？", false,
//                        "接受", "拒绝", (dialog, which) -> {
//                            ChatRoomActivity.startCharRoom(this, roomId, caseId);
//                            dialog.dismiss();
//                            ringtone.stop();
//                            v.cancel();
//                        },
//                        (dialog, which) -> {
//                            dialog.dismiss();
//                            ringtone.stop();
//                            v.cancel();
//                        });
//                mCustomDialogs.add(mCustomDialog);
//            });
//        }
    }

    protected void chooseLocImage() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_CODE_IMAGE);
    }

    protected void chooseLocVideo() {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("video/*");
        startActivityForResult(intent, REQUEST_CODE_VIDEO);
    }

    public void getImageFromCaramer() {
        mCamareFile = ClueUtil.getCameraSaveFile(this, System.currentTimeMillis());
        ClueUtil.selectImageFromCamera(this, REQUEST_CODE_CAMARE, mCamareFile);
    }

    protected void showChooseGetImageDialog(){
        String[] images = {"从相册选择", "拍照"};
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setItems(images, (dialog, which) -> {
            switch (which) {
                case 0:
                    chooseLocImage();
                    break;
                case 1:
                    getImageFromCaramer();
                    break;
            }
            dialog.dismiss();
        });
        builder.create().show();
    }

    @Override
    public void requestFailure(Throwable t) {
        Lg.i(TAG, "---requestFailure===" + t.toString());
        if (t.toString().contains(Constant.TIMEOUT_EXCEPTION)) {
            showShortToast(getString(R.string.servicer_no_response));
        }
    }

//    protected boolean checkCurrentHost() {
//        Lg.i(TAG, "---checkCurrentHost===" + ( AppDatabaseHelper.Companion.getInstance().getHostService() == null));
//        return (AppDatabaseHelper.Companion.getInstance().getHostService() != null);
//    }

//    protected void selectCityAct() {
//        if (ApiClient.apiList == null) {
//            Toast.makeText(this, "请检查网络后重试", Toast.LENGTH_SHORT).show();
//        } else {
//            startActivity(new Intent(this, SelectAreaActivity.class));
//        }
//    }

    public VersionUpdataHelper.CustomDialog showInteractionDialog(String msg, DialogInterface.OnClickListener okListener) {
        return showInteractionDialog(msg, true, "确认", "取消", okListener, (dialog, which) -> dialog.dismiss());
    }

    public VersionUpdataHelper.CustomDialog showInteractionDialogBack(String msg, DialogInterface.OnClickListener okListener) {
        return showInteractionDialog(msg, true, "确定", "取消", okListener, (dialog, which) -> dialog.dismiss());
    }

    public VersionUpdataHelper.CustomDialog showInteractionDialog(String msg, boolean cancelable, String ok, String no,
                                                                  DialogInterface.OnClickListener okListener,
                                                                  DialogInterface.OnClickListener noListener) {
        return showInteractionDialog(null, msg, cancelable, ok, 0, no, 0, okListener, noListener);
    }

    public VersionUpdataHelper.CustomDialog showInteractionDialog(String title, String msg, boolean cancelable,
                                                                  String ok, int okTextColor,
                                                                  String no, int noTextColor,
                                                                  DialogInterface.OnClickListener okListener,
                                                                  DialogInterface.OnClickListener noListener) {
        VersionUpdataHelper.CustomDialog.Builder builder = new VersionUpdataHelper.CustomDialog.Builder(this);
        builder.setTitle(title);
        builder.setMessage(msg);
        builder.setPositiveButton(ok, okListener);
        builder.setNegativeButton(no, noListener);
        builder.setButtonTextColor(okTextColor, noTextColor);
        VersionUpdataHelper.CustomDialog dialog = builder.create();
        dialog.setCancelable(cancelable);
        dialog.show();
        return dialog;
    }

    public boolean checkNet() {
        if (Tools.getNetworkType(this) == 0) {
            showInteractionDialog("网络未开启，是否开启网络", (dialog, which) -> {
                dialog.dismiss();
                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            });
            return false;
        } else {
            return true;
        }
    }

    public void checkGPS() {
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (!gpsIsEnabled) {
            showInteractionDialog("需要开启GPS才能正常使用各项功能，是否开启？"
                    , true
                    , "开启"
                    , "不开启"
                    , (dialog, which) -> {
                        dialog.dismiss();
                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivityForResult(intent, 0);
                    }, (dialog, which) -> dialog.dismiss());
        }
    }

    protected boolean checkPermission(String... permissions) {
        Lg.i(TAG, "---checkPermission===" + ArrayUtils.toString(permissions));

        if (permissions.length == 0) {
            return EasyPermissions.hasPermissions(this, Constant.sPermissionsArray);
        } else {
            return EasyPermissions.hasPermissions(this, permissions);
        }
    }

    protected void requestPermissions() {
        Lg.i(TAG, "---requestPermissions===");
        EasyPermissions.requestPermissions(this,
                getString(R.string.permission_tip),
                Constant.PERMISSIONS_CODE_BASE_A,
                Constant.sPermissionsArray);
    }

    /**
     * 无参将可进行定位
     */
    protected void startLoc() {
        if (EasyPermissions.hasPermissions(this, Constant.sPermissionsArray[0])) {
            Lg.i(TAG, "---startLoc===one");
            startLocation();
        } else {
            dismissLoadingDialog();
            requestPermissions();
            Lg.i(TAG, "---startLoc===two");
        }
    }

    /**
     * 初始化定位
     * @since 2.8.0
     */
    public void initLocation(AMapLocationListener listener) {
        Lg.i(TAG, "---initLocation===" + (listener == null));
        //初始化client
        locationClient = new AMapLocationClient(this.getApplicationContext());
        locationOption = getDefaultOption();
        //设置定位参数
        locationClient.setLocationOption(locationOption);
        // 设置定位监听
        locationClient.setLocationListener(listener == null ? locationListener : listener);
        geocoderSearch = new GeocodeSearch(this);
        geocoderSearch.setOnGeocodeSearchListener(this);
    }

    /**
     * 默认的定位参数
     * @since 2.8.0
     */
    private AMapLocationClientOption getDefaultOption() {
        AMapLocationClientOption mOption = new AMapLocationClientOption();
        mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选，设置定位模式，可选的模式有高精度、仅设备、仅网络。默认为高精度模式
        mOption.setGpsFirst(true);//可选，设置是否gps优先，只在高精度模式下有效。默认关闭
        mOption.setHttpTimeOut(30000);//可选，设置网络请求超时时间。默认为30秒。在仅设备模式下无效
        mOption.setInterval(60 * 1000);//可选，设置定位间隔。默认为2秒
        mOption.setNeedAddress(true);//可选，设置是否返回逆地理地址信息。默认是true
        mOption.setOnceLocation(false);//可选，设置是否单次定位。默认是false
        mOption.setOnceLocationLatest(false);//可选，设置是否等待wifi刷新，默认为false.如果设置为true,会自动变为单次定位，持续定位时不要使用
        AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选， 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
        mOption.setSensorEnable(false);//可选，设置是否使用传感器。默认是false
        mOption.setWifiScan(true); //可选，设置是否开启wifi扫描。默认为true，如果设置为false会同时停止主动刷新，停止以后完全依赖于系统刷新，定位位置可能存在误差
        mOption.setLocationCacheEnable(true); //可选，设置是否使用缓存定位，默认为true
        mOption.setMockEnable(true);
        return mOption;
    }

    /**
     * 定位监听
     */
    public AMapLocationListener locationListener = location -> {
        Lg.i(TAG, "---location.result===" + location.toString());
        Lg.i(TAG, "---location.getProvider===" + location.getProvider());
        if (location.getLongitude() > 1 || location.getLongitude() < -1) {
            stopLocation();
            upDateIp(location);
            if(TextUtils.isEmpty(location.getAdCode())){
                RegeocodeQuery query = new RegeocodeQuery(new LatLonPoint(location.getLatitude(),location.getLongitude()), 200,GeocodeSearch.AMAP);
                geocoderSearch.getFromLocationAsyn(query);
            }
        } else {
            /** 如果首次定位失败复写调用 */
            getLocationFails();
        }
    };


    public void getLocationFails() {

    }

    /**
     * 如果定位城市发生变化，则重新获取ip
     */
    public void upDateIp(AMapLocation location) {
        Lg.i(TAG, "---upDateIp===" + location.toString());
        SpHelper.getInstance().setLatLng(location);
        String adcode = SpHelper.getInstance().getString(SpHelper.AMAPLOCATION_INFO);
        //首次进入
        if (TextUtils.isEmpty(adcode)) {
            SpHelper.getInstance().setLocation(location);
            locationSuccess(location);
            return;
        }
        PublicUtils.changeSite(this, location);
        saveLocation(location);
    }

    private void locationSuccess(AMapLocation location) {
        Lg.i(TAG, "---locationSuccess===" + location.toString());
        EventBusHelper.sendEventBusMsg(EventBusHelper.LOCATION_SUCCESS);
        SpHelper.getInstance().putString(SpHelper.AMAPLOCATION_INFO, location.getAdCode());
    }

    public void saveLocation(AMapLocation location) {
        Lg.i(TAG, "---saveLocation===");
        if (!TextUtils.isEmpty(location.getCity())) {
            SpHelper.getInstance().setLocation(location);
        }
        /** 保存stomp消息所需上传地址(即每次都要保存=经纬度，但不一定保存地址信息应，因为地址可能为空) */
        if (location.getLatitude() != -1) {
            SpHelper.getInstance().setLatLng(location);
        }
    }

    /**
     * 开始定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    public void startLocation() {
        if (locationClient == null) {
            initLocation(null);
        }
        // 启动定位
        locationClient.startLocation();
        Lg.i(TAG, "---startLocation===");

    }

    /**
     * 停止定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    protected void stopLocation() {
        if (locationClient != null) {
            Lg.i(TAG, "---stopLocation===");
            // 停止定位
            locationClient.stopLocation();
        }
    }

    /**
     * 销毁定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void destroyLocation() {
        if (null != locationClient) {
            /**
             * 如果AMapLocationClient是在当前Activity实例化的，
             * 在Activity的onDestroy中一定要执行AMapLocationClient的onDestroy
             */
            locationClient.onDestroy();
            locationClient = null;
            locationOption = null;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        Lg.i(TAG, "---onRequestPermissionsResult===" + ArrayUtils.toString(permissions));
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void responseError(int code, String msg) {
        dismissLoaddialog();
        dismissLoadingDialog();
    }

    @Override
    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
        AMapLocation aMapLocation = new AMapLocation(BaseActivity.class.getSimpleName());
        aMapLocation.setAdCode(regeocodeResult.getRegeocodeAddress().getAdCode());
        aMapLocation.setCity(regeocodeResult.getRegeocodeAddress().getCity());
        aMapLocation.setProvince(regeocodeResult.getRegeocodeAddress().getProvince());
        aMapLocation.setDistrict(regeocodeResult.getRegeocodeAddress().getDistrict());
        aMapLocation.setLatitude(regeocodeResult.getRegeocodeQuery().getPoint().getLatitude());
        aMapLocation.setLongitude(regeocodeResult.getRegeocodeQuery().getPoint().getLongitude());
        upDateIp(aMapLocation);
    }

    @Override
    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
    }
}
